//
//  Utils.m
//  Mango
//
//  Created by 胡超 on 2017/11/29.
//  Copyright © 2017年 胡超., ltd. All rights reserved.
//

#import <objc/runtime.h>

#import "Utils.h"

void MGHookMessageEx(Class aClass, SEL sel, IMP imp, IMP *result) {
    if (aClass == nil || sel == nil || imp == nil) {
        return;
    }
    
    Method orig_Method = class_getInstanceMethod(aClass, sel);
    if (orig_Method == nil) {
        return;
    }
    
    IMP orig_imp = method_getImplementation(orig_Method);
    method_setImplementation(orig_Method, imp);
    
    if (result) {
        *result = orig_imp;
    }
}
